//
//  BIDFaultTypeViewController.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/6.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDFaultTypeViewController.h"

@interface BIDFaultTypeViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation BIDFaultTypeViewController
@synthesize faultTypeArr;
@synthesize faultTypeID;
@synthesize delegate;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"故障类型";
    _tableView.tableFooterView = [[UIView alloc] init];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return faultTypeArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    static NSString *identifier = @"identifier";
    NSUInteger row = indexPath.row;
    cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if(!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    NSDictionary *dic = faultTypeArr[row];
    cell.textLabel.text = dic[@"name"];
    if(!(ISNULL(faultTypeID)) && [faultTypeID isEqualToString:dic[@"id"]])
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSUInteger row = indexPath.row;
    NSDictionary *dic = faultTypeArr[row];
    [delegate selectFaultTypeID:dic[@"id"] name:dic[@"name"]];
    [self.navigationController popViewControllerAnimated:YES];
}

@end
